﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using GrayParrot.Configuration;
using GrayParrot.RabbitMQ.Configuration;
using GrayParrot.Scheduling;
using Test.BLL;

namespace TestRabbitMQ
{
    class Program
    {
        static void Main(string[] args)
        {
            //MessaggioTest m_test = new MessaggioTest();
            //m_test.Name = "pippo";
            //m_test.Age = 40;


            //SendMessageTest();

            //ReadMessageTest();

            ScheduleMessageTest();

            //ReadScheduledMessage();
        }

        private static void SendMessageTest()
        {
            int m_number = 2;

            ConfigurationManagerHelper pp = new ConfigurationManagerHelper();
            GrayParrot.RabbitMQ.Configuration.Subscription m_sub = pp.GetSubscription("GrayParrot-Test");

            GrayParrot.RabbitMQ.Publisher<MessaggioTest> m_pub = new GrayParrot.RabbitMQ.Publisher<MessaggioTest>(m_sub);
            for (int i = 0; i < m_number; i++)
            {
                MessaggioTest m_test = new MessaggioTest();
                m_test.Name = "pippo " + i;
                m_test.Age = 40;

                bool result = m_pub.Send(new GrayParrot.RabbitMQ.MessageBusBase<MessaggioTest>() { Body = m_test });
            }
            //Console.WriteLine(result);
        }

        private static void ReadMessageTest()
        {
            RabbitMQSubscriber m_tsb = new RabbitMQSubscriber();
            m_tsb.Init();
            //m_tsb.Dispose();

            //RabbitMQPippoPazzoSubscriber m_tsb2 = new RabbitMQPippoPazzoSubscriber();
            //m_tsb2.Init();
        }

        private static void ReadScheduledMessage()
        {
            GrayParrot.Scheduling.Scheduler m_scheduler = new GrayParrot.Scheduling.Scheduler();
            m_scheduler.Initialize();
        }

        private static void ScheduleMessageTest()
        {
            MessaggioTest m_test1 = new MessaggioTest();
            m_test1.Name = "pippo 101";
            m_test1.Age = 402;

            MessaggioTest m_test2 = new MessaggioTest();
            m_test2.Name = "pippo 102";
            m_test2.Age = 4023;

            ConfigurationManagerHelper pp = new ConfigurationManagerHelper();
            GrayParrot.RabbitMQ.Configuration.Subscription m_sub = pp.GetSubscription("GrayParrot-Test");
            GrayParrot.RabbitMQ.Publisher<MessaggioTest> m_pub = new GrayParrot.RabbitMQ.Publisher<MessaggioTest>(m_sub);
            bool result = m_pub.Send(new GrayParrot.RabbitMQ.MessageBusBase<MessaggioTest>() { Body = m_test1 }, DateTime.Now.AddMinutes(2));
            result = m_pub.Send(new GrayParrot.RabbitMQ.MessageBusBase<MessaggioTest>() { Body = m_test2 }, DateTime.Now.AddMinutes(2));
            Console.WriteLine("inviato");



            //
            //GrayParrot.Scheduling.Scheduler m_scheduler = new GrayParrot.Scheduling.Scheduler();
            //m_scheduler.Initialize();

            //JobParameters m_parameters = new JobParameters(m_test1);
            //m_parameters.Parameters.Add("subscription", "GrayParrot-Test");

            //m_scheduler.SetSchedule<GrayParrot.RabbitMQ.ScheduledMessage<MessaggioTest>>(DateTime.Now.AddMinutes(2), m_parameters);

            //
            //JobParameters m_parameters2 = new JobParameters(m_test2);
            //m_parameters2.Parameters.Add("subscription", "PippoPazzo-Test");

            //m_scheduler.SetSchedule<GrayParrot.RabbitMQ.ScheduledMessage<MessaggioTest>>(DateTime.Now.AddMinutes(1), m_parameters2);
        }
    }
}
